package br.inf.mensageiro.tree;

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

import br.inf.mensageiro.pojo.Usuario;
import br.inf.mensageiro.util.Imagem;

public class CustomTreeCellRerender extends DefaultTreeCellRenderer {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3434118216489833880L;

	public CustomTreeCellRerender() {
	}

	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
		super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
		setIcon(row != 0 ? Imagem.USER : Imagem.FOLDER);
		setToolTipText("root");
		if(value instanceof CustomMutableTreeNode){
			CustomMutableTreeNode customMutableTreeNode = (CustomMutableTreeNode) value;
			Usuario usuario = customMutableTreeNode.getUsuario();
			setText(usuario.getAlias());
			setToolTipText(usuario.getUserName());
			customMutableTreeNode.setUserObject(usuario.getUserName());
		}
		return this;
	}
}